//
//  CenterTabbar.m
//  quxiangtao
//
//  Created by xbmios on 2018/9/30.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "CenterTabbar.h"
#import <UIKit/UIKit.h>

@interface CenterTabbar ()

//@property (strong, nonatomic) UIButton *centerBtn;

@end

@implementation CenterTabbar

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setViews];
    }
    
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    if (self = [super initWithCoder:aDecoder]) {
        
//        fatalError("init(coder:) has not been implemented");
    }
    
    return self;
}

- (void)setViews {
    
    self.centerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.centerBtn addTarget:self action:@selector(centerBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIImage *normalImg = [UIImage imageNamed:@"forumSelected"];
    self.centerBtn.frame = CGRectMake(0, 0, normalImg.size.width, normalImg.size.height);
    [self.centerBtn setImage:normalImg forState:UIControlStateNormal];
    [self.centerBtn setImage:normalImg forState:UIControlStateSelected];
    [self.centerBtn setImage:normalImg forState:UIControlStateHighlighted];
    
    self.centerBtn.frame = CGRectMake((WIDTH - normalImg.size.width) / 2.0, -normalImg.size.height / 2.0, normalImg.size.width, normalImg.size.height + 20);
    [self addSubview:self.centerBtn];
    
}

- (void)centerBtnClick:(UIButton *)btn {
    return;
    NSLog(@"中间按钮点击事件");

}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    if (self.isHidden) {
        
        return [super hitTest:point withEvent:event];
    
    }else {
        
       CGPoint touch = [self.centerBtn convertPoint:point fromView:self];
        
        if ([self.centerBtn pointInside:touch withEvent:event]) {
            
            return self.centerBtn;
        
        }else {
            
            return [super hitTest:point withEvent:event];
        }
        
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
